# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-http-form_data
pkgver=2.3.0
pkgrel=1
pkgdesc='Utility-belt to build form data request bodies'
arch=(any)
url='https://github.com/httprb/form_data'
license=(MIT)
depends=(ruby)
makedepends=(ruby-rake ruby-rspec)
checkdepends=(ruby-simplecov)
options=(!emptydirs)
source=(https://github.com/httprb/form_data/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('744904b3570478ebc9d5bb08e62e6c78023c736275fe1ae89bd3c172b5cb0a26')

prepare() {
  cd form_data-$pkgver
  sed -r -e 's|git ls-files -z|find . -print0|' -i http-form_data.gemspec

  sed -i '/[cC]overalls/d' spec/spec_helper.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd form_data-$pkgver
  rake build
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    pkg/http-form_data-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd form_data-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake spec
}

package() {
  cd form_data-$pkgver
  cp -a tmp_install/* "$pkgdir"/

  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
